home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBVGAL17.ARJ / SRC_C.ARJ / VIDLIB.C < prev    next >
C/C++ Source or Header  |  1992-01-26  |  5KB  |  196 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include <mem.h>
  7. #define  VIDLIB
  8. #include "vidlib.h"
  9.  
  10. int debugtimeson=0;
  11. void static *_initstate_=NULL;
  12.  
  13. int Vinit(void)
  14. {
  15.   if ( !_vidinit) {
  16.      ReadDACs(&_olddacs);
  17.      _oldmode=BIOScrtmode;
  18.      _vidinit=1;
  19.      _initstate_=Vsavestate(_initstate_);
  20.   }
  21.   return(_oldmode);
  22. }
  23.  
  24. void Vclose(void)
  25. {
  26.   struct REGPACK r;
  27.   if ( _vidinit ) {
  28.      /* use mode set to clear screen */
  29.      VGAmode(_oldmode,NULL);
  30.      Vrestorestate(_initstate_);
  31.      if ( BIOScrtpoints != 16 ) {
  32.     if (BIOScrtpoints < 12) { /* CGA */
  33.        r.r_ax=0x1102;
  34.        r.r_bx=0;
  35.        intr(0x10,&r);
  36.     } else {
  37.        if (BIOScrtpoints < 14) { /* custom 12-point */
  38.           r.r_ax=0x1100;
  39.           r.r_cx=256;
  40.           r.r_dx=0;
  41.           r.r_bx=0x0c00;
  42.           r.r_bp=FP_OFF(&EGA12set);
  43.           r.r_es=FP_SEG(&EGA12set);
  44.           intr(0x10,&r);
  45.        } else { /* EGA */
  46.           r.r_ax=0x1101;
  47.           r.r_bx=0;
  48.           intr(0x10,&r);
  49.        } /* endif custom else EGA */
  50.     } /* endif CGA */
  51.      } /* endif non-VGA character set */
  52.      _vidinit=0;
  53.   }
  54.   return;
  55. }
  56.  
  57. void * Vsavestate(void *savebuffer)
  58. {
  59.    union REGS r;
  60.    struct SREGS s;
  61.    r.x.ax=0x1c00;
  62.    r.x.cx=0x0007; /* bit 0-hardware 1-data areas 2-DAC state and color regs*/
  63.    int86(0x10,&r,&r);
  64.    if (r.x.bx) {
  65.       if ( (savebuffer=malloc(r.x.bx*64)) == NULL) {
  66.      return(NULL);
  67.       } else {
  68.      r.x.ax=0x1c01;
  69.      r.x.cx=0x0007;
  70.      r.x.bx=FP_OFF(savebuffer);
  71.      s.es=FP_SEG(savebuffer);
  72.      int86x(0x10,&r,&r,&s);
  73.      if (r.h.al != 0x1c) {
  74.         free(savebuffer);
  75.         savebuffer=NULL;
  76.      }
  77.      return(savebuffer);
  78.       }
  79.    } else {
  80.       savebuffer=NULL;
  81.       return(NULL);
  82.    }
  83. }
  84.  
  85. void Vrestorestate(void *savebuffer)
  86. {
  87.    union REGS r;
  88.    struct SREGS s;
  89.    if (savebuffer) {
  90.      r.x.ax=0x1c02;
  91.      r.x.cx=0x0007;
  92.      r.x.bx=FP_OFF(savebuffer);
  93.      s.es=FP_SEG(savebuffer);
  94.      int86x(0x10,&r,&r,&s);
  95.    }
  96. }
  97.  
  98. int   VGAmode(unsigned int mode, char *palette)
  99. {
  100.    union REGS r;
  101.  
  102.    if ( (mode <= 0x13) && (mode >= 0)){
  103.        r.h.ah=0;
  104.        r.h.al=mode & 0x00ff;
  105.        int86(0x10,&r,&r);
  106.        if (BIOScrtmode != mode) {
  107.           return(0);
  108.        }
  109.        if ( palette != NULL ) {
  110.           Vdisable_refresh();
  111.           if (mode == 0x13) {
  112.              if ( palette == DEFAULTDAC)
  113.                 WriteDACs(&_olddacs); /* restore defaults */
  114.              else
  115.                 WriteDACs(palette);
  116.           } else {
  117.              Load_Palette(0, 16, palette);
  118.           }
  119.           Venable_refresh();
  120.        }
  121.        switch (mode) {
  122.          /* 80 x 25, text mode */
  123.          case 0x03 :  _screen_width=80;
  124.                       _memory_length=409;
  125.                       _screen_length=25;
  126.                       _screen_start=(char *)(0xB8000000L);
  127.                       break;
  128.          case 0x0f :                                /* x 2 planes */
  129.          /* 640 x 200, 1 bit per pixel x 4 planes */
  130.          case 0x0e :  _screen_width=80;
  131.                       _memory_length=819;
  132.                       _screen_length=200;
  133.                       _screen_start=(char *)(0xA0000000L);
  134.                       break;
  135.          /* 320 x 200, 1 bit per pixel x 4 planes */
  136.          case 0x0d :  _screen_width=40;
  137.                       _memory_length=1638;
  138.                       _screen_length=200;
  139.                       _screen_start=(char *)(0xA0000000L);
  140.                       break;
  141.          /* 640 x 350, 1 bit per pixel */
  142.          case 0x10 :  _screen_width=80;             /* x 4 planes */
  143.                       _memory_length=819;
  144.                       _screen_length=350;
  145.                       _screen_start=(char *)(0xA0000000L);
  146.                       break;
  147.          /* 640 x 480, 1 bit per pixel x 4 planes */
  148.          case 0x12 :  _screen_width=80;
  149.                       _memory_length=819;
  150.                       _screen_length=480;
  151.                       _screen_start=(char *)(0xA0000000L);
  152.                       break;
  153.          /* 320 x 200, 1 byte per pixel */
  154.          case 0x13 :  _screen_width=320;
  155.                       _memory_length=204;
  156.                       _screen_length=200;
  157.                       _screen_start=(char *)(0xA0000000L);
  158.                       break;
  159.        }
  160.        if (vgadebug != NULL) {
  161.           sprintf(tdbg,"\nVGAmode: mode=%u, _sw=%u, _sl=%u, _ss=%lx\n",
  162.                        mode, _screen_width, _memory_length, _screen_start);
  163.           fputs(tdbg,vgadebug);
  164.        }
  165.        return(1);
  166.    } else
  167.        return(0);
  168. }
  169.  
  170. int isVGA(void)
  171. {
  172.    union REGS r;
  173.    r.x.ax=0x1a00;
  174.    int86(0x10,&r,&r);
  175.    if ( (r.h.al == 0x1a )&& (r.h.bl > 7))
  176.       return(1);
  177.    else
  178.       return(0);
  179. }
  180.  
  181. void Start_vgadebug(char *path)
  182. {
  183.    if (debugtimeson)
  184.       vgadebug=fopen(path,"a");
  185.    else
  186.       vgadebug=fopen(path,"w");
  187.    debugtimeson++;
  188. }
  189.  
  190. void Close_vgadebug(void)
  191. {
  192.    fclose(vgadebug);
  193. }
  194.  
  195.  
  196.